<template>
  <div class="user">
    <h3 class="title">Users:</h3>
    <div class="user-items">
      <div class="user-item header">
        <div class="index">序号</div>
        <div class="name">姓名</div>
        <div class="age">年龄</div>
      </div>
      <div class="user-item data-item" v-for="(user, idx) in users" :key="idx" :class="{selected: selectedId === user.id}" @click="select(user)">
        <div class="index">{{ idx + 1 }}</div>
        <div class="name">{{ user.name }}</div>
        <div class="age">{{ user.age }}</div>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  props: {
    users: {
      default: () => {
        return []
      }
    },
    value: {
      type: Object,
      default: null,
    }
  },
  data() {
    return {
      selectedId: null,
    }
  },
  mounted() {
  },
  methods: {
    select(user) {
      this.selectedId = user.id
      this.$emit('input', user)
    },
  },
}
</script>
<style lang="less" scoped>
.user-items {
  padding: 4px;
  border: solid 1px #33afc7;
  border-radius: 6px;
  .user-item {
    display: flex;
    justify-content: flex-start;
    line-height: 26px;
    font-size: 15px;
    cursor: pointer;
    transition: all ease 300ms;

    &.header {
      font-weight: bold;
    }
    
    &.data-item {
      border-radius: 4px;
      &:hover {
        background-color: #eff;
      }

      &.selected {
        background-color: #3B92FF;
        color: white;
      }

    }
    

    > div {
      padding-right: 10px;
    }

    .index {
      width: 40px;
      display: flex;
      justify-content: center;
    }

    .name {
      width: 80px;
    }

    .age {
    }
  }
}
</style>